<template>
  <div>
    <el-form :model="form" ref="form" :rules="rules" label-width="80px">
      <el-form-item label="文章标题" prop="title">
        <el-input v-model="form.title" placeholder="请输入文章标签"></el-input>
      </el-form-item>
      <el-form-item label="文章内容" prop="articleBody">
        <quill-editor
          ref="quillEditor"
          style="height:300px;margin-bottom:125px"
          v-model="form.articleBody"
        ></quill-editor>
      </el-form-item>
      <el-form-item label="视频地址">
        <el-input placeholder="请输入视频地址" v-model="form.videoURL"></el-input>
      </el-form-item>
      <el-form-item style="text-align:center">
        <el-button @click="qx">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import { quillEditor } from 'vue-quill-editor'
import { add } from '@/api/hmmm/articles'
export default {
    data() {
        return {
            //表单信息
            form: {
                title: '',
                articleBody: '',
                videoURL: ''
            },
            //验证
            rules: {
                title: [
                    {
                        required: true,
                        message: '请输入文章标题',
                        trigger: 'blur'
                    }
                ],
                articleBody: [
                    {
                        required: true,
                        message: '请输入文章内容',
                        trigger: 'blur'
                    }
                ]
            }
        }
    },

    components: {
        quillEditor
    },
    props: {},
    created() {},
    methods: {
        //添加
        async submit() {
            this.$refs.form.validate(async valid => {
                let { data: res } = await add(this.form)
                this.$message.success('添加文章成功')
                this.$emit('close')
            })
        },
        qx() {
            this.$emit('close')
        }
    }
}
</script>

<style lang="less" scoped>
</style>